<?php


namespace App\Http\Controllers\Weapp;


use App\Tool\Json;
use Illuminate\Support\Arr;

class Mention extends Base
{


    function getMentionData(){


        $now=time();

        $timeout=\Cache::get('mention:timeout','21:00');

        $timeout=strtotime($timeout);

        $list=\App\Model\Mention::get();

        if($list) $list=$list->toArray();

        $enable_list=[];

        foreach ($list as $key=>$value){

            $start_time=$value['mention_start'];

            $start_time=strtotime($start_time);

            $end_time=$value['mention_end'];

            $end_time=strtotime($end_time);

            $list[$key]['sort']=$start_time;

            $list[$key]['end_time']=$end_time;

        }

        $list=array_values(Arr::sort($list,function ($v){

            return $v['sort'];

        }));


        foreach ($list as $key=>$value){

            $sort=$value['sort'];

            $end_time=$value['end_time'];

            if($key==0&&$now>$timeout){


                break;
            }

            if($now<$end_time){

                $value['date']=date('Y.m.d');

                $value['name']='今天';

                $enable_list[0][]=$value;

            }


        }

        foreach ($list as $key=>$value){

            $value['date']=now()->addDays()->format('Y.m.d');

            $value['name']='明天';

            $enable_list[1][]=$value;

        }

        foreach ($list as $key=>$value){

            $value['name']='后天';

            $value['date']=now()->addDays(2)->format('Y.m.d');

            $enable_list[2][]=$value;

        }



//        dd($enable_list);
        return Json::code(1,'success',array_values($enable_list));
    }


}
